package cn.mcartoon.controller;

import cn.mcartoon.dto.Result;
import cn.mcartoon.dto.ResultUtils;
import cn.mcartoon.utils.redis.RedisUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api
@RestController
@RequestMapping("/demo")

public class DemoController {

    private Logger logger = LoggerFactory.getLogger(DemoController.class);

    @Autowired
    RedisUtils redisUtils;

    @ApiOperation(value = "获取姓名和年龄",produces = "application/json",notes = "获取姓名年龄")
    @GetMapping("/hello")
    public Object hello(String name,Integer age){
        logger.info("name:"+name,"age"+age);
        System.out.println("哈哈哈哈");
        return "name:"+name+"age"+age;
    }

    @ApiOperation(value = "redis的存值",produces = "application/json",notes = "redis存值")
    @GetMapping("/setredis")
    public Result<Object> setRedis(String key,String value){
        if(!redisUtils.set(key,value)){
            return ResultUtils.returnFail("测试redis失败");
        }
        return ResultUtils.returnSuccess("测试redis成功");
    }

    @ApiOperation(value = "redis的取值",produces = "application/json",notes = "redis取值")
    @GetMapping("/getredis")
    public Result<Object> getRedis(String key){
        return ResultUtils.returnDataSuccess(redisUtils.get(key));
    }

}
